﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.Windows;

namespace QLThuoc_report
{
    public partial class frm_TKeThuocTheoNgay : Form
    {
        public frm_TKeThuocTheoNgay()
        {
            InitializeComponent();
        }
        private  DateTime _NgayBan;

        public DateTime NgayBan
        {
            get { return _NgayBan; }
            set { _NgayBan = value; }
        }
        private void TKeThuocTheoNgay_Load(object sender, EventArgs e)
        {
            txt_NgayBan.Hide();
            txt_NgayBan.Text = NgayBan.ToString();
           SqlConnection  conn = new SqlConnection("Data Source =(local);Initial Catalog=QLThuoc;Integrated Security=true");
           SqlDataAdapter da = new SqlDataAdapter("SELECT     dbo.tbl_Thuoc.TenThuoc AS 'Tên Thuốc',tbl_CTHoaDonBH.NgayBan As 'Ngày Bán', SUM(dbo.tbl_CTHoaDonBH.SoLuong) AS 'Số Lượng Đã Bán',   SUM(((dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien)*10) / 100 + dbo.tbl_CTHoaDonBH.SoLuong * dbo.tbl_Thuoc.GiaTien) AS 'Tổng Tiền' FROM         dbo.tbl_CTHoaDonBH INNER JOIN  dbo.tbl_Thuoc ON dbo.tbl_CTHoaDonBH.MaThuoc = dbo.tbl_Thuoc.MaThuoc where tbl_CTHoaDonBH.NgayBan='" + txt_NgayBan.Text + "' GROUP BY dbo.tbl_Thuoc.TenThuoc,tbl_CTHoaDonBH.NgayBan ", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            //lay duong dan du chuy?n sang máy tính nào c?ng ko b? l?i, ko có c?ng ðc nhýng sang máy tính khác s? ko ch?y ðc
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin")) + "TkeThuocTheoNgay11.rpt";
            TkeThuocTheoNgay11 report = new TkeThuocTheoNgay11();
            report.SetDataSource(dt);
            crystalReportViewer1.ReportSource = report;
        }
    }
}
